Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(sink): impl RowEncoder for JsonEncoder #12264

Merged
merged 4 commits into from
Sep 14, 2023

Conversation

xiangjinwu
Copy link
Contributor

@xiangjinwu xiangjinwu commented Sep 13, 2023

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

Part A of #12125 targeting #11995:

  • Introduce traits RowEncoder, SerTo<String>, SerTo<Vec<u8>>.
  • Introduce struct JsonEncoder as an implementation of RowEncoder
    • This replaces pk_to_json and record_to_json in sink::utils

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)
  • My PR contains critical fixes that are necessary to be merged into the latest release. (Please check out the details)

Documentation

  • My PR needs documentation updates. (Please use the Release note section below to summarize the impact on users)

Release note

If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.

@codecov
Copy link

codecov bot commented Sep 13, 2023

Codecov Report

Merging #12264 (74b5bfe) into main (173ad4e) will increase coverage by 0.01%.
The diff coverage is 74.33%.

@@            Coverage Diff             @@
##             main   #12264      +/-   ##
==========================================
+ Coverage   69.71%   69.73%   +0.01%     
==========================================
  Files        1411     1413       +2     
  Lines      236351   236390      +39     
==========================================
+ Hits       164783   164835      +52     
+ Misses      71568    71555      -13     
Flag Coverage Δ
rust 69.73% <74.33%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
src/connector/src/sink/kafka.rs 35.61% <0.00%> (-0.66%) ⬇️
src/connector/src/sink/kinesis.rs 0.00% <0.00%> (ø)
src/connector/src/sink/mod.rs 37.37% <ø> (ø)
src/connector/src/sink/encoder/mod.rs 38.46% <38.46%> (ø)
src/connector/src/sink/encoder/json.rs 86.23% <86.23%> (ø)
src/connector/src/sink/remote.rs 53.59% <100.00%> (-0.39%) ⬇️
src/connector/src/sink/utils.rs 69.16% <100.00%> (-7.88%) ⬇️

... and 8 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

}
}

fn datum_to_json_object(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All lines below (i.e. datum_to_json_object and mod tests) are moved from sink::utils without changing a single character.

src/connector/src/sink/encoder/mod.rs Show resolved Hide resolved

fn encode(
&self,
row: RowRef<'_>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

row: impl Row?

Copy link
Contributor Author

@xiangjinwu xiangjinwu Sep 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

impl Row seems not enough here. It needs to be either &impl Row or impl Row + Copy. Each style appears exactly twice in existing code base. Do we have a preference here?

Some thoughts:

  • impl Row + Copy can be specified in caller, but &impl Row must be here
  • impl Row + Copy accepts non-ref but &impl Row does not
  • impl Row + Copy is a superset of &impl Row thanks to impl<R: Row> Row for &R

@@ -405,26 +258,24 @@ pub async fn gen_upsert_message_stream<'a>(
pk_indices: &'a [usize],
chunk: StreamChunk,
_opts: UpsertAdapterOpts,
key_encoder: JsonEncoder,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May pass impl RowEncoder instead of JsonEncoder to make the code more general.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is included in later part of the refactor.

Copy link
Contributor

@wenym1 wenym1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest LGTM.

src/connector/src/sink/encoder/mod.rs Show resolved Hide resolved
@xiangjinwu xiangjinwu added this pull request to the merge queue Sep 14, 2023
Merged via the queue into main with commit 1aadfd0 Sep 14, 2023
@xiangjinwu xiangjinwu deleted the refactor-sink-format-encode-0-RowEncoder branch September 14, 2023 06:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants